<template>
    <div style="width: 100%;height: 100%">
        <Row class="button_row">
                <span style="float: left;">
                   <Button type="primary" icon="ios-add" @click="handleAdd">
                新增
            </Button>
                </span>
            <!--<span style="float: right;">-->
            <!--<Button type="primary" style="" @click="searchQueryNew">查询</Button>-->
            <!--&lt;!&ndash;<Button type="primary" style="margin-left: 8px" @click="searchResetNew">重置</Button>&ndash;&gt;-->
            <!--</span>-->
        </Row>
        <div class="table_div">
            <vxe-table border
                       auto-resize
                       row-id="id"
                       :row-key="true"
                       show-overflow="tooltip"
                       highlight-hover-row
                       align="center"
                       header-align="center"
                       ref="xTree"
                       :loading="Loading"
                       :data="tableData">
                <vxe-table-column field="name" title="任务名称" align="center"/>
                <vxe-table-column field="className" title="任务类名" align="center"/>
                <vxe-table-column field="cron" title="crom表达式" align="center"/>
                <vxe-table-column field="remarks" title="描述" align="center"/>
                <vxe-table-column field="arg" title="参数信息" align="center"/>
                <vxe-table-column field="state" title="状态" align="center">
                    <template #default="{ row }">
                        <Button type="success" size="small" ghost v-if="row.state=='1'">已启动</Button>
                        <Button type="error" size="small" ghost v-else>已暂停</Button>
                    </template>
                </vxe-table-column>
                <vxe-table-column title="操作" align="center" fixed="right">
                    <template #default="{row}">
                        <Button type="success" size="small" style="margin-right: 5px" v-if="row.state=='1'"
                                @click="handleBegin(row.id,'0')">暂停
                        </Button>
                        <Button type="success" size="small" style="margin-right: 5px" v-else
                                @click="handleBegin(row.id,'1')">启动
                        </Button>
                        <Button type="info" size="small" style="margin-right: 5px" @click="handleEdit(row)">编辑</Button>
                        <Button type="warning" size="small" style="margin-right: 5px" @click="handleDetail(row)">详情
                        </Button>
                        <Button type="error" size="small" style="margin-right: 5px" @click="handleDelete(row.id)">删除
                        </Button>
                    </template>
                </vxe-table-column>
            </vxe-table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
        <quartz-manager-modal ref="modalForm" @ok="modalFormOk"/>
    </div>
</template>

<script>
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import {getAction, postAction} from '@/api/request'
    import QuartzManagerModal from './modules/QuartzManagerModal.vue'

    export default {
        mixins: [CommonMixin],
        components: {QuartzManagerModal},
        data() {
            return {
                queryParam: {},
                Loading: true,
                url: {
                    list: "/api/ac/subsistence/QuartzManagerServiceImpl/page",
                    delete: "/api/ac/subsistence/QuartzManagerServiceImpl/delete",
                    suspended: "/api/ac/subsistence/QuartzManagerServiceImpl/createSuspended",
                    start: "/api/ac/subsistence/QuartzManagerServiceImpl/createStart",
                },
            }
        },
        methods: {
            handleBegin: function (id, state) {
                var url = this.url.start;
                var title = "确定启动定时任务？";
                var success = "启动成功!";
                if (state == "0") {
                    url = this.url.suspended;
                    title = "确定暂停定时任务？";
                    success = "暂停成功!";
                }
                this.$Modal.confirm({
                    title: title,
                    onOk: () => {
                        var that = this;
                        postAction(url, {id: id}).then((res) => {
                            if (res.data.errcode == 0) {
                                //重新计算分页问题
                                that.reCalculatePage(1);
                                that.$Message.success(success);
                            } else {
                                that.$Message.error(res.data.errmsg);
                            }
                        });
                    }
                })
            },
        },
        created() {
            this.loadData();
        },
    }
</script>

<style scoped>

</style>